home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 7661 / 7661.xpi / chrome / isreaditlater.jar / content / RILgr.js < prev    next >
Encoding:
Text File  |  2009-12-15  |  7.8 KB  |  192 lines

  1. function RILgr()
  2. {
  3.     this.empty = 'chrome://isreaditlater/skin/book16_hollow_trans.png';
  4.     this.full = 'chrome://isreaditlater/skin/book16_urlbar.png';
  5.     this.TO = null;
  6. }
  7.  
  8. RILgr.prototype = {
  9.         
  10.     _init : function() {
  11.                     
  12.     },
  13.     
  14.     _initpage : function() {
  15.         if (RIL.APP.PREFS.getBool('integrate-gr')) {
  16.             if (content.document.getElementById('entries')) {
  17.                 content.document.getElementById('entries').addEventListener('DOMNodeInserted', RILgr.readyUpdate, false);
  18.             }
  19.             RIL.xulId("appcontent").removeEventListener("DOMContentLoaded", RILgr.readyInit, false);
  20.             content.document.addEventListener('keydown', RILgr.Toggle, true);
  21.             
  22.             RILgr.readyUpdate();
  23.         }
  24.     },
  25.     
  26.     check : function() {
  27.         if (RIL.APP.PREFS.getBool('integrate-gr')) {
  28.             var u = RIL.currentURL();
  29.             
  30.             if (u.match(/^https?:\/\/reader\.google\.(.+)/) || u.match(/^https?:\/\/([^.]+\.)?google\.(.+)\/reader/)) {
  31.                 RIL.xulId("appcontent").addEventListener("DOMContentLoaded", RILgr.readyInit, false);
  32.                 return;
  33.             }
  34.         }
  35.         RIL.xulId("appcontent").removeEventListener("DOMContentLoaded", RILgr.readyInit, false);
  36.         clearInterval(this.checkingForRefresh);
  37.     },
  38.     
  39.     readyInit : function() {
  40.         setTimeout(RIL.APP.genericClosure(RILgr, '_initpage'), 1900);
  41.     },
  42.     
  43.     readyUpdate : function() {
  44.         clearInterval(RILgr.TO);
  45.         RILgr.TO = setTimeout(RIL.APP.genericClosure(RILgr, 'updateEntries'), 100);
  46.     },
  47.     
  48.     updateEntries : function() {
  49.         var org, titleLink, checkmark, viewType, pageTitle, sec, source, ctn, friends;
  50.         this.marks = {};
  51.         
  52.         var entries = this.getElementsByClassName(content.document, 'entry', null, 'ril-set');
  53.         if (entries.length > 0) {           
  54.             
  55.             for(var i = 0; i<entries.length; i++) {
  56.                 
  57.                 if (!entries[i].className.match('ril-set')) {
  58.                     
  59.                     //Create Checkmark
  60.                     checkmark = content.document.createElement('img');
  61.                     
  62.                     //Determine View Type
  63.                     org = this.getElementsByClassName(entries[i], 'entry-original')[0];
  64.                     titleLink = this.getElementsByClassName(entries[i], 'entry-title-link')[0];
  65.                     
  66.                     if (org || titleLink) {
  67.                     
  68.                         if (org) {
  69.                             
  70.                             viewType = 'list';
  71.                             
  72.                             url = org.href;
  73.                             pageTitle = this.getElementsByClassName(entries[i], 'entry-title')[0].innerHTML;
  74.                             sec = this.getElementsByClassName(entries[i], 'entry-secondary')[0];
  75.                             source = this.getElementsByClassName(entries[i], 'entry-source-title')[0];
  76.                             friends = this.getElementsByClassName(entries[i], 'entry-source-friends')[0];
  77.                             ctn = content.document.getElementById('entries').className.match('single-source') ? sec : source;
  78.                             
  79.                             checkmark.style.marginRight = '9px';
  80.                             
  81.                         } else if (titleLink) {
  82.  
  83.                             viewType = 'expanded';
  84.                             
  85.                             url = titleLink.href;
  86.                             pageTitle = titleLink.innerHTML.replace(/<([^>]+)>/, '').replace(/(^\s+|\s+$)/, '') + '';
  87.                             ctn = this.getElementsByClassName(entries[i], 'entry-icons')[0];                               
  88.                             
  89.                         }
  90.                     
  91.                         //Set Checkmark attributes
  92.                         let inList = RIL.APP.LIST.itemByUrl(url);
  93.                         checkmark.src = inList ? this.full : this.empty;
  94.                         checkmark.width = 15;
  95.                         checkmark.height = 15;
  96.                         checkmark.style.cursor = 'pointer';
  97.                         checkmark.style.verticalAlign = 'top';
  98.                         checkmark.className = 'RIL-checkmark';
  99.                         if (friends)
  100.                         {
  101.                             checkmark.style.cssFloat = 'left';
  102.                             checkmark.style.marginTop = '3px';
  103.                         }
  104.                         
  105.                         //Get Info and Nodes
  106.                         checkmark.setAttribute('url', url);
  107.                         checkmark.setAttribute('pageTitle', pageTitle);
  108.                         checkmark.addEventListener("click", this.clickMark, true);
  109.                         
  110.                         //Add Checkmark
  111.                         ctn.insertBefore( checkmark , ctn.firstChild );
  112.                     }
  113.                         
  114.                     entries[i].className += ' ril-set';
  115.                 }
  116.             }
  117.             
  118.             clearInterval(this.checkingForRefresh)
  119.             this.checkingForRefresh = setInterval( this.checkForRefresh, 1000 );
  120.         }
  121.     },
  122.     
  123.     checkForRefresh : function()
  124.     {
  125.         try{
  126.         if (RILgr.listWasRefreshed)
  127.         {
  128.             RILgr.listWasRefreshed = false;
  129.             
  130.             let marks = content.document.getElementsByClassName('RIL-checkmark');
  131.             let url, checkmark;
  132.             
  133.             for(let i=0; i<=marks.length; i++)
  134.             {
  135.                 checkmark = marks[i];
  136.                 
  137.                 if (checkmark)
  138.                 {
  139.                     url = checkmark.getAttribute('url');
  140.                     checkmark.src = RIL.APP.LIST.itemByUrl(url) ? RILgr.full : RILgr.empty;
  141.                 }
  142.             }
  143.         }
  144.         }catch(e){Components.utils.reportError(e);}
  145.     },
  146.     
  147.     clickMark : function(e, obj) {
  148.         if (e) {
  149.             e.stopPropagation();
  150.             obj = this;
  151.         }
  152.         if (obj.src == RILgr.full) {
  153.             let item = RIL.APP.LIST.itemByUrl( obj.getAttribute('url') );
  154.             if (item)
  155.                 RIL.APP.LIST.mark( item.itemId );
  156.             else
  157.                 RIL.APP.d('could not find ' + obj.getAttribute('url'));
  158.             obj.src = RILgr.empty;                
  159.         } else {
  160.             RIL.saveLink( obj.getAttribute('url') , obj.getAttribute('pageTitle') );
  161.             obj.src = RILgr.full;
  162.         }
  163.     },
  164.     
  165.     Toggle : function(e) {
  166.         var item;
  167.         if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
  168.             if ( String.fromCharCode(e.keyCode).toUpperCase() ==  RIL.APP.PREFS.get('hotkey_gr').toUpperCase() ) {
  169.                 item = RILgr.getElementsByClassName(content.document.getElementById('current-entry'), 'RIL-checkmark')[0];
  170.                 if (item) {
  171.                     RILgr.clickMark(null, RILgr.getElementsByClassName(content.document.getElementById('current-entry'), 'RIL-checkmark')[0] );
  172.                 }
  173.             }
  174.         }
  175.     },
  176.     
  177.     // -- //
  178.     
  179.     getElementsByClassName  : function (parent, className, nodeName, notClassName) {
  180.         var result = [], tag = nodeName||'*', node, seek, i;
  181.         var rightClass = new RegExp( '(^| )'+ className +'( |$)' );
  182.         var wrongClass = new RegExp( '(^| )'+ notClassName +'( |$)' );
  183.         seek = parent.getElementsByTagName( tag );
  184.         for(var i=0; i<seek.length; i++ )
  185.           if( rightClass.test( (node = seek[i]).className ) && !wrongClass.test( (node = seek[i]).className ) )
  186.             result.push( seek[i] );
  187.         return result;
  188.     },      
  189.         
  190. }
  191.  
  192. RILgr = new RILgr();